package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

/**
 * @ClassName :  RecommendUserService
 * @Author : Tenebrous
 * @Date: 2020/12/10 20:46
 * @Description : 被推荐用户的业务层
 */
@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    TodayBest queryTodayBest(Long userId) {
        // 通过dubbo去调用queryWithMaxScore方法，返回今日佳人在mongodb中对应字段的信息
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(userId);
        if (null == recommendUser) {
            return null;
        }
        // 设置今日最佳用户的id，得分和缘分值
        // 创建今日佳人对象
        TodayBest todayBest = new TodayBest();
        // 如果得分为96.2时，需要显示的得分是96 去除小数
        double score = Math.floor(recommendUser.getScore());
        // 获取Long型的缘分值
        todayBest.setFateValue(Double.valueOf(score).longValue());
        // 将返回的mongodb对应的userId设置进todayBest中的id中
        todayBest.setId(recommendUser.getUserId());

        return todayBest;
    }

    /**
     * 查找推荐朋友信息
     * @param id                登录者id
     * @param page              页数
     * @param pageSize          页大小
     * @return                  分页信息
     */
    PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pageSize) {
        return this.recommendUserApi.queryPageInfo(id, page, pageSize);
    }

    /**
     * 查询推荐好友的缘分值
     *
     * @param userId
     * @param toUserId
     * @return
     */
    public double queryScore(Long userId, Long toUserId) {
        return this.recommendUserApi.queryScore(userId, toUserId);
    }
}
